using System;
using System.Linq.Expressions;
using FluentValidation.Validators;

namespace Dogshow.Model.Validation.MyVallidators
{
    public class RasaRoditeljaValidator : PropertyValidator
    {
        public RasaRoditeljaValidator() : this("Rasa roditelja ne odgovara rasi psa"){}

        public RasaRoditeljaValidator(string errorMessageResourceName, Type errorMessageResourceType) : base(errorMessageResourceName, errorMessageResourceType)
        {
        }

        public RasaRoditeljaValidator(string errorMessage) : base(errorMessage)
        {
        }

        public RasaRoditeljaValidator(Expression<Func<string>> errorMessageResourceSelector) : base(errorMessageResourceSelector)
        {
        }

        protected override bool IsValid(PropertyValidatorContext context)
        {
            var idRase = (int) context.PropertyValue;
            var pas = (Pas)context.Instance;
            if (pas == null) return true;
            if (pas.Otac != null && idRase != pas.Otac.IdRase) return false;
            if (pas.Majka != null && idRase != pas.Majka.IdRase) return false;
            return true;
        }
    }
}